﻿using System.Collections.Generic;
using Fuse8.DomainFramework.Common.Locator;
using Fuse8.DomainFramework.Domain;

namespace Fuse8.DomainFramework.CacheService
{
	/// <summary>
	/// 
	/// </summary>
	public class CacheKeyFacade : ICacheKeyService
	{
		private static ICacheKeyService _current;
		private static ICacheKeyService Current
		{
			get
			{
				return _current ?? (_current = DependencyServiceLocator.Current.IsRegistered<ICacheKeyService>() ? DependencyServiceLocator.Current.GetInstance<ICacheKeyService>() : new DefaultCacheKeyService());
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="parameters"></param>
		/// <returns></returns>
		public string GenerateCacheKey(params object[] parameters)
		{
			return Current.GenerateCacheKey(parameters);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		public string GenerateDependencyCacheKey(IEntityObject entity)
		{
			return Current.GenerateDependencyCacheKey(entity);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="tag"></param>
		/// <returns></returns>
		public string GenerateDependencyCacheKeyTag(string tag)
		{
			return Current.GenerateDependencyCacheKeyTag(tag);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cacheKey"></param>
		/// <returns></returns>
		public string GenerateAddCacheKyeTag(string cacheKey)
		{
			return Current.GenerateAddCacheKyeTag(cacheKey);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <typeparam name="TEntity"></typeparam>
		/// <param name="entity"></param>
		/// <returns></returns>
		public IList<string> GenerateCacheKeysForLinkedDependency<TEntity>(TEntity entity) where TEntity : class, IEntityObject
		{
			return Current.GenerateCacheKeysForLinkedDependency(entity);
		}
	}
}